class Solution {

    int solve1(string A,int K){
        int cnt=0;
        int pos=0;
        int ans=0;
        for(int i=0;i<A.length;i++){
            if(A[i]=='F')cnt++;
            while(cnt>K){
                if(A[pos]=='F')cnt--;
                pos++;
            }
            ans=max(ans,i-pos+1);
        }
        return ans;
    }
    int solve2(string A,int K){
        int cnt=0;
        int pos=0;
        int ans=0;
        for(int i=0;i<A.length;i++){
            if(A[i]=='T')cnt++;
            while(cnt>K){
                if(A[pos]=='T')cnt--;
                pos++;
            }
            ans=max(ans,i-pos+1);
        }
        return ans;
    }
    int maxConsecutiveAnswers(string answerKey, int k) {
        int ans=0;
        ans=max(solve1(answerKey,k),solve2(answerKey,k));
        return ans;
    }
}
